import os


def get_relative_paths_of_files_in_subdirectories(directory_path):
    relative_paths = []

    try:
        # 获取当前目录下的所有条目
        entries = os.listdir(directory_path)

        for entry in entries:
            subdirectory_path = os.path.join(directory_path, entry)

            # 检查是否是目录
            if os.path.isdir(subdirectory_path):
                # 获取该子目录中的所有文件
                for root, dirs, files in os.walk(subdirectory_path):
                    # 计算文件的相对路径
                    for file in files:
                        file_relative_path = os.path.relpath(os.path.join(root, file), directory_path)
                        relative_paths.append(file_relative_path)
                    # 不继续深入子目录
                    break

    except FileNotFoundError:
        print(f"The directory {directory_path} does not exist.")

    #return relative_paths
    directory_structure = {}

    for file_path in relative_paths:
        # 分离目录和文件名
        dir_name, file_name = os.path.split(file_path)

        # 去掉文件扩展名
        file_name_without_ext = os.path.splitext(file_name)[0]

        # 如果目录名不在字典中，初始化一个空列表
        if dir_name not in directory_structure:
            directory_structure[dir_name] = []

        # 将文件名添加到对应目录名的列表中
        directory_structure[dir_name].append(file_name_without_ext)
    return directory_structure



# 使用示例
directory_path = './'  # 当前目录
relative_paths = get_relative_paths_of_files_in_subdirectories(directory_path)
print(relative_paths)
for i in relative_paths:
    print(i)
